// 购物车模块数据
const db = require('./db.js')

module.exports = {
  // 获取购物车信息
  GetShoppingCart: async (user_id) => {
    const sql = 'select * from shoppingCart where user_id = ?'
    return await db.query(sql, user_id)
  },
  // 查询用户购物车的某个商品
  FindShoppingCart: async (user_id, product_id) => {
    const sql = 'select * from shoppingCart where user_id = ? and product_id = ?'
    return await db.query(sql, [user_id, product_id])
  },
  // 添加购物
  AddShoppingCart: async (user_id, product_id) => {
    const sql = 'insert into shoppingCart values(null,?,?,1)'
    return await db.query(sql, [user_id, product_id])
  },
  // 添加数量
  UpdateShoppingCart: async (NewNum, user_id, product_id) => {
    const sql = 'update shoppingCart set num =? where user_id =? and product_id =?'
    return await db.query(sql, [NewNum, user_id, product_id])
  },
  // 删除
  DeleteShoppingCart: async (user_id, product_id) => {
    const sql = 'delete from shoppingCart where user_id =? and product_id =?'
    return await db.query(sql, [user_id, product_id])
  }
}
